package br.com.srv.config;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;

import br.com.srv.exception.FFServiceException;

public final class Configuracao {
	
	public final static String IP_ADDRESS = "localhost";
	public final static String PORTA = "9000";
	public final static String URL_JDBC = "jdbc:mysql://localhost/ffService";
	public final static String USER_JDBC = "root";
	public final static String PWD_JDBC = "root";
	public final static String DRIVER_CLASS_NAME = "com.mysql.jdbc.Driver";
	
	static int conexaoCount = 0;
	
	public static Connection criarConexao() throws FFServiceException {
		
		Connection connection = null;
		try {
			Class.forName(DRIVER_CLASS_NAME);
			connection = DriverManager.getConnection(URL_JDBC, USER_JDBC, PWD_JDBC);
			//System.out.println("N° Conexoes correntes " + ++conexaoCount);
		} catch (SQLException e) {
			throw new FFServiceException(e,
					"Não foi possível realizar a conexao com o banco de dados.");
		} catch (ClassNotFoundException e1) {
			throw new FFServiceException(e1,
					"Não foi possível localizar a classe " + DRIVER_CLASS_NAME +".");
		}		
			
		return connection;
	}
	
	public static void fecharConexao(Connection connection)  {
		try {
			connection.close();
		} catch (SQLException e) {
			e.printStackTrace();
		}
	}
	
}
